<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <ul>
        <li></li>
        <li></li>
        <li></li>
    </ul>
    <script>
        var arr = [1,2,3];
        // arr.forEach(function (ele,index,self) {
        //     this[index].innerHTML = ele;
        // },document.getElementsByTagName('li'))
        //第二个参数可以改变函数里面this指向

        Array.prototype.myForEach = function (func) {
            var _arr = this,
            len = _arr.length,
            param2 = arguments[1] || window;
            for(var i = 0;i < len;i ++) {
                func.apply(param2,[_arr[i],i,_arr]);
            }
        }
        arr.myForEach(function (ele,index,self) {
            console.log(ele,index,self);
        },document.getElementsByTagName('li'))
    
    </script>
</body>
</html>